package com.wuli.food.common.apiModel;

import io.swagger.annotations.ApiModel;

import java.io.Serializable;
import java.util.HashMap;
import java.util.Map;

@ApiModel(description= "返回响应数据")
public class R<T> extends HashMap<String, Object> implements Serializable{
	private static final long serialVersionUID = 1L;

	public R() {
		put("code", 0);
		put("message", "success");
		put("success", true);
		put("data", null);
	}

	public  R Error() {
		return Error(-1, "未知异常，请联系管理员");
	}

	public  R Error(String msg) {
		return Error(-1, msg);
	}

	public  R Error(int code) {
		return Error(code, "未知异常，请联系管理员");
	}


	public  R Error(int code, String msg) {
		R r = new R();
		r.put("code", code);
		r.put("message", msg);
		r.put("success", false);
		return r;
	}

	public  R Success(String msg) {
		R r = new R();
		r.put("message", msg);
		return r;
	}

	public  R Success(Map<String, Object> map) {
		R r = new R();
		r.put("data", map);
		return r;
	}

	public  R Success() {
		return new R();
	}

	public  R Success(Object value) {
		R r = new R();
		r.put("data", value);
		return r;
	}

	@Override
	public R put(String key, Object value) {
		super.put(key, value);
		return this;
	}

	public R put(Object value) {
		super.put("data", value);
		return this;
	}

}